package edu.chl.jadetalk.db;

import edu.chl.jadetalk.core.*;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.LocalBean;
import javax.ejb.Startup;

/**
 * Temporary class to populate the database.
 * @author Daniel
 */
@Singleton
@LocalBean
@Startup
public class PopulateDBTestData {

    @EJB
    IUserFacade user;
    
    @EJB
    IImageFacade image;
    
    //@PostConstruct
    private void init() {
        
        Logger.getAnonymousLogger().log(Level.WARNING, "Populating database with test data.");
        
        User user1 = new User();
        user1.setUsername("Sven");
        user1.setEmail("sven@sdf.se");
        user1.setPassword("pass123");
        
        User user2 = new User();
        user2.setUsername("Benny");
        user2.setEmail("benny@sdf.se");
        user2.setPassword("pass321");
        
        
        
        List<Rating> ratings1 = new LinkedList<Rating>();
        Rating r1 = new Rating();
        r1.setUser(user1);
        r1.setValue((byte) 1);
        ratings1.add(r1);
        
        List<Rating> ratings2 = new LinkedList<Rating>();
        Rating r2 = new Rating();
        r2.setUser(user2);
        r2.setValue((byte) 2);
        ratings2.add(r2);
        
        CommentThread commentThread1 = new CommentThread();
        List<Comment> comments1 = new LinkedList<Comment>();
        Comment c1 = new Comment();
        c1.setCommentText("Fin bild.");
        c1.setUser(user2);
        Comment c12 = new Comment();
        c12.setCommentText("Tackar.");
        c12.setUser(user1);
        comments1.add(c1);
        comments1.add(c12);
        commentThread1.setComments(comments1);
        
        CommentThread commentThread2 = new CommentThread();
        List<Comment> comments2 = new LinkedList<Comment>();
        Comment c2 = new Comment();
        c2.setCommentText("Ful bild.");
        c2.setUser(user1);
        comments1.add(c2);
        commentThread2.setComments(comments2);
        
        
        
        Image image1 = new Image();
        image1.setImageLocation("e1f4698.jpg");
        image1.setUser(user1);
        image1.setRatings(ratings1);
        image1.setCommentThread(commentThread1);
        
        Image image2 = new Image();
        image2.setImageLocation("ad33b4b4.jpg");
        image2.setUser(user2);
        image2.setRatings(ratings2);
        image2.setCommentThread(commentThread2);
        
        
        
        user.create(user1);
        user.create(user2);
        
        image.create(image1);
        image.create(image2);
        
    }
    
}
